package com.cheng.config;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

import com.cheng.dto.ExperienceData;
import com.cheng.dto.ResumeData;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.Numberings;
import com.deepoove.poi.data.Pictures;
import com.deepoove.poi.data.TextRenderData;
import com.deepoove.poi.data.style.Style;

/**
 * 输出（简历）=模板+数据
 * @author cheng-qiang
 * @date 2022年08月15日15:37
 */
public class ResumeIterableExample {

    public static void main(String[] args) {
       try {
           ResumeData data = new ResumeData();
           data.setPortrait(Pictures.ofLocal("src/main/resources/img.png").size(100, 100).create());
           data.setName("坚持是一种技术");
           data.setJob("BUG工程师");
           data.setPhone("18080809090");
           data.setSex("男");
           data.setProvince("成都");
           data.setBirthday("2010.08.19");
           data.setEmail("yiwannuofulasi@163.com");
           data.setAddress("四川省成都市");
           data.setEnglish("CET6 620");
           data.setUniversity("美国斯坦福大学");
           data.setProfession("生命工程");
           data.setEducation("博士");
           data.setRank("班级排名 1/36");
           data.setHobbies("音乐、画画、乒乓球、旅游、读书\nhttps://chengqiangxj.gitee.io/");

           // 技术栈部分
           TextRenderData textRenderData = new TextRenderData("SpringBoot、SprigCloud、Mybatis");
           Style style = Style.builder().buildFontSize(10).buildColor("7F7F7F").buildFontFamily("微软雅黑").build();
           textRenderData.setStyle(style);
           data.setStack(Numberings.of(textRenderData, textRenderData, textRenderData).create());

           /*
            * {{?experiences}} {{company}} {{department}} {{time}} {{position}}
            * {{*responsibility}} {{/experiences}}
            */
           List<ExperienceData> experiences = new ArrayList<>();
           ExperienceData data0 = new ExperienceData();
           data0.setCompany("香港微软");
           data0.setDepartment("Office 事业部");
           data0.setTime("2001.07-2020.06");
           data0.setPosition("BUG工程师");
           textRenderData = new TextRenderData("负责生产BUG，然后修复BUG，同时有效实施招聘行为");
           textRenderData.setStyle(style);
           data0.setResponsibility(Numberings.of(textRenderData, textRenderData).create());
           ExperienceData data1 = new ExperienceData();
           data1.setCompany("自由职业");
           data1.setDepartment("OpenSource 项目组");
           data1.setTime("2015.07-2020.06");
           data1.setPosition("研发工程师");
           textRenderData = new TextRenderData("开源项目的迭代和维护工作");
           textRenderData.setStyle(style);
           TextRenderData textRenderData1 = new TextRenderData("持续集成、Swagger文档等工具调研");
           textRenderData1.setStyle(style);
           data1.setResponsibility(Numberings.of(textRenderData, textRenderData1, textRenderData).create());
           experiences.add(data0);
           experiences.add(data1);
           experiences.add(data0);
           experiences.add(data1);
           data.setExperiences(experiences);
           XWPFTemplate template = XWPFTemplate.compile("src/main/resources/templates/iterable_resume.docx").render(data);
           FileOutputStream out = new FileOutputStream("src/main/resources/templates/out_example_resume_iterable.docx");
           template.write(out);
           out.flush();
           out.close();
           template.close();
       }catch (Exception ignored){
       }
    }
}
